#pragma once

#include <string.h>
#include "math.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"

#include "driver/i2c.h"
#include "driver/spi_master.h"
#include "driver/ledc.h"

#include "esp_lcd_types.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_touch_ft5x06.h"

#include "common/i2c_peripheral.h"
#include "common/pca9557_device.h"
#include "assets/yingwu.h"
#include "display/lvgl_demo_keypad_encoder.h"

#include "esp_lvgl_port.h"
#include "demos/lv_demos.h"
#define BSP_LCD_PIXEL_CLOCK_HZ     (80 * 1000 * 1000)
#define BSP_LCD_SPI_NUM            (SPI3_HOST)
#define LCD_CMD_BITS               (8)
#define LCD_PARAM_BITS             (8)
#define BSP_LCD_BITS_PER_PIXEL     (16)
#define LCD_LEDC_CH          LEDC_CHANNEL_0

#define BSP_LCD_H_RES              (320)
#define BSP_LCD_V_RES              (240)

#define BSP_LCD_SPI_MOSI            (GPIO_NUM_40)
#define BSP_LCD_SPI_CLK             (GPIO_NUM_41)
#define BSP_LCD_SPI_CS              (GPIO_NUM_NC)
#define BSP_LCD_DC                  (GPIO_NUM_39)
#define BSP_LCD_RST                 (GPIO_NUM_NC)
#define BSP_LCD_LEDC_BACKLIGHT      (GPIO_NUM_42)  


#define BSP_LCD_DRAW_BUF_HEIGHT    (20)

esp_err_t bsp_display_brightness_init(void);
esp_err_t bsp_display_brightness_set(int brightness_percent);
esp_err_t bsp_display_backlight_off(void);
esp_err_t bsp_display_backlight_on(void);

esp_err_t bsp_lcd_init(void);
void bsp_lvgl_start(void);

void lcd_set_color(uint16_t color);
void lcd_draw_pictrue(int x_start, int y_start, int x_end, int y_end, const unsigned char *gImage);



void st7789(void);
void SetupUI(void);